<template>
	<view style="flex: auto; background-color: #f5f5f5; height: 100vh">
		<u-col>
			<view style="margin: 20rpx;background-color: #ffffff">

				<u-row>
					<u--image customStyle="margin: 10px 10px 10px 10px" :src="this.userHead" width="40px" height="40px"
						shape="circle" @click="headClick">
					</u--image>
					<u--text v-if="isEmpty(this.token)" suffixIcon="arrow-right" iconStyle="font-size: 18px" text="点我登陆"
						@click="loginClick">
					</u--text>

					<view v-if="!isEmpty(this.token)" style="width: 560rpx; display: flex; flex-direction: row;">
						<u--text @click="btnClick('pages/mine/edit_user')" customStyle="margin: 0px 0px 0px 20rpx"
							:bold="true" :text="this.infoData.userName">
						</u--text>
						<u--image customStyle="margin: 0rpx 5rpx 0px 20rpx" width="60rpx" height="60rpx"
							:src="getUserLevel(this.level)"></u--image>
					</view>

					<view v-if="0"
						style="display: flex; flex-direction: row; justify-content: flex-end; margin-right: 20rpx; margin-top: -30rpx;">
						<u-icon color="#07C160" size="20" name="setting"></u-icon>
					</view>
				</u-row>

				<u-row>
					<u-col span="4">
						<view
							style="display: flex; justify-content: center;flex-direction: column;align-items: center; margin-bottom: 20rpx; margin-top: 50rpx;">
							<u--text :text="'￥: '+incomeMoney" :bold="true"></u--text>
							<u--text text="累计收益"></u--text>
						</view>
					</u-col>

					<u-col span="4">
						<view @click="btnClick('pages/mine/with_draw_his',balanceMoney)"
							style="display: flex; justify-content: center;flex-direction: column;align-items: center; margin-bottom: 20rpx; margin-top: 50rpx;">
							<u--text :text="'￥: '+balanceMoney" :bold="true"></u--text>
							<u--text text="我的余额"></u--text>
						</view>

					</u-col>

					<u-col span="4">
						<view @click="btnClick('pages/mine/my_group')"
							style="display: flex; justify-content: center;flex-direction: column;align-items: center; margin-bottom: 20rpx; margin-top: 50rpx;">
							<u--text :text="myGroupCount" :bold="true"></u--text>
							<u--text text="我的团队"></u--text>
						</view>

					</u-col>



				</u-row>
			</view>


			<view style="margin: 20rpx;background-color: #ffffff">
				<u--text text="我的订单" customStyle="margin: 20rpx 0px 0px 20rpx" :bold="true"></u--text>
				<u-row>
					<u-col span="3">
						<view class="centerView">
							<view style="display: flex; flex-direction: column; margin: 20rpx;
							 justify-content: center; align-items: center;" @click="btnClick('pages/order/my_order',0)">
								<u--image src="/static/icon_all_order.png" width="60rpx" height="60rpx"
									style="margin: 0rpx;"></u--image>
								<u--text text="全部" customStyle="margin: 10px 0px 0px 0px"></u--text>

							</view>
						</view>
					</u-col>
					<u-col span="3">
						<view class="centerView">
							<view
								style="display: flex; flex-direction: column; margin: 10rpx; justify-content: center; align-items: center;"
								@click="btnClick('pages/order/my_order',2)">
								<u--image src="/static/icon_todo_order.png" width="60rpx" height="60rpx"
									style="margin: 0rpx;"></u--image>
								<u--text text="待审核" customStyle="margin: 10px 0px 0px 0px"></u--text>

							</view>
						</view>
					</u-col>
					<u-col span="3">
						<view class="centerView">
							<view
								style="display: flex; flex-direction: column; margin: 10rpx; justify-content: center; align-items: center;"
								@click="btnClick('pages/order/my_order',3)">
								<u--image src="/static/icon_ready_order.png" width="60rpx" height="60rpx"
									style="margin: 0rpx;"></u--image>
								<u--text text="已审核" customStyle="margin: 10px 0px 0px 0px"></u--text>

							</view>
						</view>
					</u-col>

					<u-col span="3">
						<view class="centerView">
							<view
								style="display: flex; flex-direction: column; margin: 10rpx; justify-content: center; align-items: center;"
								@click="btnClick('pages/order/my_order',4)">
								<u--image src="/static/icon_error_order.png" width="60rpx" height="60rpx"
									style="margin: 0rpx;"></u--image>
								<u--text text="已失效" customStyle="margin: 10px 0px 0px 0px"></u--text>

							</view>
						</view>
					</u-col>
				</u-row>
			</view>


			<view style="margin: 20rpx; background-color: #ffffff">
				<u--text text="其他管理" customStyle="margin: 20rpx 0px 0px 20rpx" :bold="true"></u--text>
				<u-row>
					<u-col span="3">
						<view class="centerView">
							<view style="display: flex; flex-direction: column; margin: 20rpx;
								 justify-content: center; align-items: center;" @click="btnClick('pages/mine/my_group')">
								<u--image src="/static/icon_my_group.png" width="60rpx" height="60rpx"
									style="margin: 0rpx;"></u--image>
								<u--text text="我的团队" customStyle="margin: 10px 0px 0px 0px"></u--text>

							</view>
						</view>
					</u-col>
					<u-col span="3">
						<view class="centerView">
							<view
								style="display: flex; flex-direction: column; margin: 10rpx; justify-content: center; align-items: center;"
								@click="pageClick('pages/webview/webview','平台简介',1)">
								<u--image src="/static/icon_pf_detail.png" width="60rpx" height="60rpx"
									style="margin: 0rpx;"></u--image>
								<u--text text="平台简介" customStyle="margin: 10px 0px 0px 0px"></u--text>

							</view>
						</view>
					</u-col>
					<u-col span="3">
						<view class="centerView">
							<view
								style="display: flex; flex-direction: column; margin: 10rpx; justify-content: center; align-items: center;"
								@click="pageClick('pages/webview/webview','项目操作',3)">
								<u--image src="/static/icon_play_help.png" width="60rpx" height="60rpx"
									style="margin: 0rpx;"></u--image>
								<u--text text="项目操作" customStyle="margin: 10px 0px 0px 0px"></u--text>

							</view>
						</view>
					</u-col>

					<u-col span="3">
						<view class="centerView">
							<view
								style="display: flex; flex-direction: column; margin: 10rpx; justify-content: center; align-items: center;"
								@click="pageClick('pages/webview/webview','联系客服',4)">
								<u--image src="/static/icon_kf_msg.png" width="60rpx" height="60rpx"
									style="margin: 0rpx;"></u--image>
								<u--text text="客服消息" customStyle="margin: 10px 0px 0px 0px"></u--text>

							</view>
						</view>
					</u-col>
				</u-row>
			</view>
		</u-col>

		<u-button v-if="!isEmpty(this.token)" style="width: 80%; margin-top: 120rpx;" @click="logoutClick"
			class="custom-style" type="primary" text="退出登录"></u-button>

		<u-modal :show="showChangeHead" :showCancelButton="true" @cancel="changeHead(0)" @confirm="changeHead(1)"
			:title="changeHeadTitle" :content='changeHeadContent'></u-modal>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				userHead: "/static/icon_head.png",
				token: "",
				incomeMoney: 0,
				balanceMoney: 0,
				myGroupCount: 0,
				infoData: {},
				changeHeadTitle: "修改头像",
				changeHeadContent: "确认修改头像吗？",
				showChangeHead: false,
				jtStatus: 1,
				level: 0,

			}
		},
		onShow() {
			this.token = uni.getStorageSync('login_token')
			console.log("token", this.token);
			if (this.token !== 'undefined' && this.token != null && this.token !== '') {
				this.$u.api.apiGetUser().then(res => {
					if (res.code == 1) {
						this.level = res.data.userLevel
						this.infoData = res.data
						this.userHead = res.data.userHead
						if (res.data.todayCoin > 0) {
							this.todayMoney = res.data.todayCoin
						}
						if (res.data.userCoin > 0) {
							this.totalMoney = res.data.userCoin
						}
						this.jtStatus = res.data.jtStatus;
					} else {
						uni.setStorage('login_token', "")
						this.token = ""
					}
				})
			}

		},
		methods: {
			getUserLevel(level) {
				switch (level) {
					case 0:
						return "/static/icon_level0.png";
					case 1:
						return "/static/icon_level1.png";
					case 2:
						return "/static/icon_level2.png";
					case 3:
						return "/static/icon_level3.png";
				}
			},
			logoutClick() {
				uni.setStorageSync('login_token', "")
				this.token = ""
				this.pageClick('pages/login/login', '', 0)
				this.userHead = "/static/icon_head.png"
			},
			pageClick(route_url, param, type) {
				console.log(route_url);
				let router = '' + route_url + ''
				console.log(router)

				uni.$u.route(router, {
					pageTitle: param,
					pageType: type,
				});

			},
			headClick() {
				if (this.token !== 'undefined' && this.token != null && this.token !== '') {
					this.showChangeHead = true;
				} else {
					this.$u.toast("请先登陆!")
				}

			},
			changeHead(type) {
				this.showChangeHead = false;
				if (type == 1) {
					uni.chooseImage({
						count: 1, // 图片数量
						sourceType: ['album', 'camera'], //从相册选择或者拍照
						success: (res) => {
							const tempFilePaths = res.tempFilePaths;
							console.log("upload", tempFilePaths[0])

							uni.uploadFile({
								url: 'http://tuikeshiwan.com/api/public/upload', //上传图片api
								filePath: tempFilePaths[0],
								name: "file",
								success: (res) => {
									this.userHead = res.data;
									this.submitClick(this.userHead);
								},
								fail: (err) => {
									console.log("uploadFile error", err)
								}
							});
						}
					});

				}
			},
			submitClick(changeUserHead) {
				let param = {
					userHead: changeUserHead,
				}
				this.$u.api.apiUpdateUser(param).then(res => {
					if (res.code == 1) {
						console.log("onLoad=" + res.data)
						this.$u.toast("修改成功!")
						//返回上一页
					} else {
						this.$u.toast(res.msg)
					}
				})
			},
			loginClick() {
				console.log('login');
				uni.$u.route({
					url: 'pages/login/login',
				})
			},
			btnClick(url, type) {
				console.log(url);
				let router = '' + url + ''
				console.log(router)
				uni.$u.route(router, {
					recordType: type,
				});
			},
			isEmpty(str) {
				return (!str || 0 === str.length);
			},
			showHideMoney() {
				this.$u.api.apiDisJE().then(res => {
					if (res.code == 1) {
						console.log(res.data);
						this.jtStatus = res.data.jtStatus;
					} else {

					}
				})
			}

		}
	}
</script>

<style>

</style>